Page({

    /**
     * 页面的初始数据
     */
    data: {
        name: '',
        job_name: '',
        phone: '',
        email: '',
        graduated: '',
        highest_degree: '',
        major: '',
        job_skill: '',
        work_experience: '',
        self_assessment: '',
        gender: ['女性', '男性'], //性别选择范围
        sex: "", //性别选择
        birth: "", //出生年月
        address: ["广东省", "广州市", "天河区"], //居住地址
        isSave: true,
        cid:''
    },
    save() {
        let {
            name,
            job_name,
            phone,
            email,
            graduated,
            highest_degree,
            major,
            job_skill,
            work_experience,
            self_assessment,
            sex,
            birth,
            address,cid
        } = this.data
        wx.reLaunch({
            url: `../resumeList/resumeList?cid=${Date.parse(new Date())}&&job_name=${this.data.job_name}`
          })
        // if(cid){
        //     wx.request({
        //         url: `https://localhost:8080/curri/update/${cid.toString()}`,
        //         header: {
        //             "Authorization": `Bearer ${wx.getStorageSync('token')}`
        //         },
        //         method: 'POST',
        //         data: {
        //             name,
        //             cid,
        //             sex: parseInt(sex),
        //             job_name,
        //             birth,
        //             address: address.toString(),
        //             phone,
        //             email,
        //             graduated,
        //             highest_degree,
        //             major,
        //             job_skill,
        //             work_experience,
        //             self_assessment
        //         },
        //         success: (res) => {
        //         if (res.data.code == '200') {
        //                  wx.showToast({
        //                     title: '保存成功',
        //                     duration: 5000,
        //                 })
        //                 setTimeout(()=>{
        //                 wx.reLaunch({
        //                   url: '../resumeList/resumeList',
        //                 })
        //                 },2000)
                    
        //             }
        //         }
        //     })
        // }else{
        //     wx.request({
        //         url: 'https://localhost:8080/curri',
        //         header: {
        //             "Authorization": `Bearer ${wx.getStorageSync('token')}`
        //         },
        //         method: 'POST',
        //         data: {
        //             name,
        //             sex: parseInt(sex),
        //             job_name,
        //             birth,
        //             address: address.toString(),
        //             phone,
        //             email,
        //             graduated,
        //             highest_degree,
        //             major,
        //             job_skill,
        //             work_experience,
        //             self_assessment
        //         },
        //         success: (res) => {
        //         if (res.data.code == '200') {
        //                  wx.showToast({
        //                     title: '保存成功',
        //                 })
        //                 setTimeout(()=>{
        //                     wx.reLaunch({
        //                       url: '../resumeList/resumeList',
        //                     })
        //                     },2000)
        //             }
        //         }
        //     })
        // }
      
    },
    hanleInput(e) {
        let type = e.currentTarget.dataset.type
        this.setData({
            [type]: e.detail.value
        })
        this.btn();
    },
    //性别选择
    bindPickerChange: function (e) {
        this.setData({
            sex: e.detail.value
        })
        this.btn()
    },
    //时间选择
    bindDateChange: function (e) {
        this.setData({
            birth: e.detail.value
        })
        this.btn()
    },
    //区域选择
    bindRegionChange: function (e) {
        this.setData({
            address: e.detail.value
        })
        this.btn()
    },
    btn() {
        let {
            name,
            job_name,
            phone,
            email,
            graduated,
            highest_degree,
            major,
            job_skill,
            work_experience,
            self_assessment,
            sex,
            birth,
            address
        } = this.data
        if (name != '' && job_name != '' && phone != '' && email != '' && graduated != '' && highest_degree != '' && major != '' && job_skill != '' && work_experience != '' && self_assessment != '' && !isNaN(sex)&& birth != '' && address != '') {
            this.setData({
                isSave: false
            })
        } else {
            this.setData({
                isSave: true
            })
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let cid = parseInt(options.cid)
        this.setData({cid})
        // if (options.cid!=undefined) {
        //     wx.request({
        //         url: `https://localhost:8080/curri/${cid}`,
        //         header: {
        //             "Authorization": `Bearer ${wx.getStorageSync('token')}`
        //         },
        //         success:(res)=>{
        //             console.log(res.data.data);
        //             let {
        //                 name,
        //                 job_name,
        //                 phone,
        //                 email,
        //                 graduated,
        //                 highest_degree,
        //                 major,
        //                 job_skill,
        //                 work_experience,
        //                 self_assessment,
        //                 sex,
        //                 birth,
        //                 address
        //             } = res.data.data
        //             this.setData({
        //                 address:address.split(','),
        //                 birth,
        //                 sex,
        //                 name,
        //                 job_name,
        //                 phone,
        //                 email,
        //                 graduated,
        //                 highest_degree,
        //                 major,
        //                 job_skill,
        //                 work_experience,
        //                 self_assessment,
        //             },()=>{this.btn()})
                    
        //         }
        //     })
        // }

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})